package com.dtx.iterator.myself;

import com.dtx.iterator.gongyongde.Aggregate;
import com.dtx.iterator.gongyongde.Book;
import com.dtx.iterator.gongyongde.Iterator;

import java.util.ArrayList;
import java.util.List;

public class MyBookShelf implements Aggregate {

    private List<Book> list;


    public MyBookShelf(int maxsize){
        this.list = new ArrayList<>(maxsize);
    }

    public Book getBookAt(int index){
        return list.get(index);
    }

    public void appendBook(Book book){
        list.add(book);
    }

    public int getLength(){
        return list.size();
    }


    @Override
    public Iterator iterator() {
        return new MyBookShelfIterator(this);
    }
}
